#include "include.h"
#include "huart_audio_out.h"
/*
 * 文件名称: huart_audio_out.c
 * 功能描述: 本文件为HUART DMA 输出数字信号 处理模块
    注意当前芯片为8916A2 / 5632G 只有一组HUART
    开启本功能后，在线eq调试会失效哦~
 ****************************************************************************************
    code：
    buf:
    time :
 */
#if ADAPTER_HUART_OUTPUT_EN
#define HUART_AUDIO_BAUD                2000000          //haurt波特率
#define HUART_SAMPLES                   120*2            //16bit = 8bit * 2
#define HUART_TX_PORT                   HUART_TR_PB4     //huart发射引脚
#define HUART_RX_PORT                   HUART_TR_PE6     //huart接收引脚
huart_audio_out_cfg_t huart_audio_out_cfg;
AT(.text.huart_proc.input)
void huart_audio_out_input(u8 *ptr, u32 samples, int ch_mode, void *param)
{
    s16 *rptr = (s16 *)ptr;
    if(!huart_audio_out_cfg.mute){
        huart_putcs(ptr,samples*2);
    }
    if (huart_audio_out_cfg.callback) {
        huart_audio_out_cfg.callback((u8 *)rptr, samples, ch_mode, param);
    }
}

AT(.text.huart_set.callback)
void huart_audio_out_output_callback_set(audio_callback_t callback)
{
    huart_audio_out_cfg.callback = callback;
}

AT(.text.huart_set.mute)
void huart_audio_out_mute_set(uint8_t mute)
{
    huart_audio_out_cfg.mute = mute;
}

AT(.text.huart_init)
void huart_audio_out_init(u8 sample_rate, u16 samples)
{
    memset(&huart_audio_out_cfg,0,sizeof(huart_audio_out_cfg));
    huart_init_do(HUART_TX_PORT,HUART_RX_PORT, HUART_AUDIO_BAUD, NULL, 0, 0);
}

AT(.text.huart_exit)
void huart_audio_out_exit(void)
{

}
#endif // I2S_TX_AUDIO_EN

